package com.elinkway.infinitemovies.selfdata;

import com.elinkway.infinitemovies.bean.NewAdDataBean;
import com.elinkway.infinitemovies.bean.ServerPayload;
import com.elinkway.infinitemovies.selfdata.bean.MyDataRecord;
import com.elinkway.infinitemovies.selfdata.dao.RealmDaoManager;
import com.elinkway.infinitemovies.utils.UmengEventPoster;
import com.elinkway.infinitemovies.utils.Utils;

import java.util.HashMap;

/**
 * Author: liuxiaojiang(xiao)
 * Date: 2017-07-11
 * Time: 11:28
 * Description: FIXME
 */
public class AdRequestStatis {
    //代理层广告返回的统计

    public static void selfResponseReport(NewAdDataBean result, String position){
        MyDataRecord record = MyDataRecordCreater.build(MyDataRecord.class);
        record.setAd_po(position);
        record.setAcode(SelfDataConstant.AC_ADREQUEST);
        if (Utils.GDT_AD.equalsIgnoreCase(result.provider)) {
            record.setAd_pro(SelfDataConstant.AD_GDT);
        } else if (Utils.BAIDU_AD.equalsIgnoreCase(result.provider)){
            record.setAd_pro(SelfDataConstant.AD_BD);
        } else if (Utils.GDT_SPLASH_AD.equalsIgnoreCase(result.provider)){
            record.setAd_pro(SelfDataConstant.AD_GDT);
            record.setAd_po("launch");
        } else if (Utils.HZ_AD.equals(result.provider)) {
            record.setAd_pro(SelfDataConstant.AD_HZ);
        } else if (Utils.YZ_AD.equals(result.provider)) {
            record.setAd_pro(SelfDataConstant.AD_YOUZI);
        } else if (Utils.XF_AD.equals(result.provider)) {
            record.setAd_pro(SelfDataConstant.AD_XF);
        }else if (Utils.SERVER_AD.equals(result.provider)){
            record.setAd_pro(SelfDataConstant.AD_SERVER);
            ServerPayload serverPayload = (ServerPayload)result.payload;
            if(serverPayload != null){
                record.setAd_url(serverPayload.lp);
            }
        } else if (Utils.TT_AD.equals(result.provider)) {
            record.setAd_pro(SelfDataConstant.AD_TT);
        }else {
            return;
        }
        RealmDaoManager.addMyDataRecord(record);
    }

    public static void selfReportAdShow(String adProducer, String position) {
        MyDataRecord record = MyDataRecordCreater.build(MyDataRecord.class);
        record.setAcode(SelfDataConstant.AC_ADSHOW);
        record.setAd_pro(adProducer);
        record.setAd_po(position);
        RealmDaoManager.addMyDataRecord(record);
    }

    public static void selfReportAdClick(String adProducer, String position) {
        MyDataRecord record = MyDataRecordCreater.build(MyDataRecord.class);
        record.setAcode(SelfDataConstant.AC_ADCLICK);
        record.setAd_pro(adProducer);
        record.setAd_po(position);
        RealmDaoManager.addMyDataRecord(record);
    }

}
